﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Text.RegularExpressions;
using CoDbObject;

namespace Colligate.DataSource.DriverTraining
{
    public static class UtilityInstance
    {
        public static object GetInstance(string className, string taskGuid, IDataSourceLayer dataLayer, IDataService dataService)
        {
            var types = Assembly.GetExecutingAssembly().GetTypes();
            object obj = null;
            foreach (var t in types)
            {
                if (className == t.Name)
                {
                    obj = Activator.CreateInstance(t, taskGuid, dataLayer, dataService);
                    break;
                }
            }
            return obj;
        }

        public static string ExtractWord(string originalString, int wordIndex)
        {
            Regex mRegex = new Regex("[A-Z][a-z]+");
            MatchCollection mMactchCol = mRegex.Matches(originalString);
            return (mMactchCol.Count > wordIndex) ? mMactchCol[wordIndex].Value : "";
        }

        public static int GetWordsCount(string originalString)
        {
            Regex mRegex = new Regex("[A-Z][a-z]+");
            MatchCollection mMactchCol = mRegex.Matches(originalString);
            return mMactchCol.Count;
        }
    }
}
